<template>
<!-- 已处理 -->
   <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          &nbsp; &nbsp; &nbsp;
          审批ID:
            <el-input
              placeholder="请输入内容"
              prefix-icon="el-icon-search"
              style="width:250px; margin-top:28px; margin-left:10px ;"
              v-model="voteInfo.id">
            </el-input>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
           审批类型：
            <el-select v-model="voteInfo.title" placeholder="审批类型">
              <el-option label="全部" value=""></el-option>
              <el-option label="请假" value="请假"></el-option>
              <el-option label="出差" value="出差"></el-option>
              <el-option label="加班" value="加班"></el-option>
              <el-option label="外出" value="外出"></el-option>
              <el-option label="入职" value="入职"></el-option>
              <el-option label="转账" value="转账"></el-option>
              <el-option label="会议室预订" value="会议室预订"></el-option>
              <el-option label="用车" value="用车"></el-option>
            </el-select>
             &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
           审批状态：
            <el-select v-model="voteInfo.status" placeholder="审批状态">
              <el-option label="全部" value="0"></el-option>
              <el-option label="审批中" value="1"></el-option>
              <el-option label="审批通过" value="2"></el-option>
              <el-option label="审批拒绝" value="3"></el-option>
              <el-option label="审批撤销" value="4"></el-option>
            </el-select>
               &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              <el-button type="primary" @click="pendingList()">查询</el-button>
           
              <el-button type="primary" @click="resetQuery()">重置</el-button>
            
        </div>
      </el-col>
    </el-row>
     <el-row>
      <el-col :span="24">
        <div style="padding-left:60px;padding-top:50px;" class="grid-content bg-purple-dark-two">
           <el-table
           :header-cell-style="{background: '#f4f4f4'}"
           v-loading="loading"
            :data="tableData"
            style="width:1200px;">
              <el-table-column
                type="selection"
                width="55">
              </el-table-column>
            <el-table-column fixed prop="id" label="审批ID" width="150"></el-table-column>
            <el-table-column prop="title" label="标题" width="180"> </el-table-column>
            <el-table-column prop="tuser.username" label="发起人" width="150"></el-table-column>
            <el-table-column prop="sponsorTime" label="发起时间" width="180"> </el-table-column>
            <el-table-column prop="status" label="状态" width="180">
               <template slot-scope="scope">
                 <el-tag size="medium" v-if="scope.row.status==1" effect="dark">审批中</el-tag>
                 <el-tag size="medium" type="success" v-if="scope.row.status==2" effect="dark">已同意</el-tag>
                 <el-tag size="medium" type="info" v-if="scope.row.status==4" effect="dark">已撤销</el-tag>
                 <el-tag size="medium"  type="danger" v-if="scope.row.status==3" effect="dark">已拒绝</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" width="100"></el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="180">
              <template slot-scope="scope">
                <el-button
                  @click.native.prevent="handleEdit(scope.$index, scope.row)"
                  type="text" >
                  详情
                </el-button>
                <el-button
                  @click.native.prevent="updateStatus1(scope.$index, scope.row)"
                  type="text" v-if="scope.row.status==1">
                  拒绝
                </el-button>
                <el-button
                  @click.native.prevent="updateStatus2(scope.$index, scope.row)"
                  type="text" v-if="scope.row.status==1">
                  同意
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <div class="block">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[5, 10, 20, 50]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </el-col>
        </div>
      </el-col>
    </el-row>

   </div>
</template>

<script>
import axios from 'axios'
import { parseTime } from '@/utils/ruoyi';
export default {
  data(){
    return{
      loading:true,
       voteInfo: {
           id:"",
           title:"",
           status:"",
           approver:""  //传当前登录人的id
       },
       tableData: [],
        pageNum: 1,
        pageSize: 5,
        total: 0,
    }
  },
  created(){
      this.pendingList();
  },
   methods: {
      //跳转到详情页
      handleEdit(index, row) {
        console.log(index, row);
        this.$router.push({path: '/Particulars',query:{ id:row.id}})
      },
      //每页条数改变时触发 选择一页显示多少行
      handleSizeChange(val) {
        this.pageSize = val;
        this.pendingList();
      },
      //当前页改变时触发 跳转其他页
      handleCurrentChange(val) {
        this.pageNum = val;
        this.pendingList();
      },
      deleteRow(index, rows) {
        rows.splice(index, 1);
      },
      //重置
      resetQuery() {
        this.voteInfo.id = "";
        this.voteInfo.status = "";
        this.voteInfo.title = "";
        this.pendingList();
      },
      // 审核中心 我的待处理列表查询，分页 条查
      pendingList() {
         var a=JSON.parse(localStorage.getItem("user"))
         this.voteInfo.approver=a.id
        axios.post("auditCenter/findTAuditCenterPaginationList2?pageNum="+this.pageNum+"&pageSize="+this.pageSize, this.voteInfo)
        .then((res) => {
              this.tableData = res.data.rows;
              for (const value of this.tableData) {
                value.sponsorTime = parseTime(value.sponsorTime,'{y}-{m}-{d} {h}:{i}:{s}')
              }
              console.log(this.tableData)
                this.total = res.data.total;
                this.loading=false;
          });
      },
      // 审批   拒绝
      updateStatus1(index, row){
        row.status=3
        axios
          .post("auditCenter/updateStatusById", row)
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                message: "恭喜你，" + res.data.msg,
                type: "success",
              });
              this.pendingList();
            } else {
              this.$message.error("错了哦，" + res.data.msg);
            }
          });
      },
      
      //审批  同意
      updateStatus2(index, row){
        row.status=2
        axios
          .post("auditCenter/updateStatusById", row)
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                message: "恭喜你，" + res.data.msg,
                type: "success",
              });
              this.pendingList();
            } else {
              this.$message.error("错了哦，" + res.data.msg);
            }
          });
      }
    },

}
</script>

<style scoped>

.block{
  padding-left: 800px;
}
.el-row {
    margin-bottom: 20px;
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: white;
    height: 100px;
  }
  .bg-purple-dark-two {
    background: white;
    height: 500px;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
   
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
</style>